package com.dxy.filter;

import com.dxy.utils.UserUtil;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author DELL
 */
@WebFilter({"/admin/index","/admin/views/*"})
public class CharSetFilter implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response=(HttpServletResponse) resp;
        String userName = UserUtil.getUserName(request.getSession());
        request.setCharacterEncoding("UTF-8");
        if (userName!=null){
            chain.doFilter(req,resp);
        }else{
            response.sendError(404,"很遗憾权限不足");
        }




    }

    @Override
    public void init(FilterConfig config) throws ServletException {

    }

}
